package com.website.web.back.controller.website;

import com.website.common.annotation.Log;
import com.website.common.core.controller.BaseController;
import com.website.common.core.domain.AjaxResult;
import com.website.common.core.page.TableDataInfo;
import com.website.common.enums.BusinessType;
import com.website.common.utils.poi.ExcelUtil;
import com.website.custom.domain.WBusiness;
import com.website.custom.service.IWBusinessService;
import com.website.custom.service.IWConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务范围Controller
 * 
 * @author ruoyi
 * @date 2025-03-25
 */
@Controller
@RequestMapping("/back/custom/business")
public class WBusinessController extends BaseController
{
    private String prefix = "back/website/business";

    @Autowired
    private IWBusinessService wBusinessService;
    @Autowired
    private IWConfigService wConfigService;

    @RequiresPermissions("custom:business:view")
    @GetMapping()
    public String business()
    {
        return prefix + "/business";
    }

    /**
     * 查询业务范围列表
     */
    @RequiresPermissions("custom:business:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WBusiness wBusiness)
    {
        startPage();
        List<WBusiness> list = wBusinessService.selectWBusinessList(wBusiness);
        return getDataTable(list);
    }

    /**
     * 导出业务范围列表
     */
    @RequiresPermissions("custom:business:export")
    @Log(title = "业务范围", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WBusiness wBusiness)
    {
        List<WBusiness> list = wBusinessService.selectWBusinessList(wBusiness);
        ExcelUtil<WBusiness> util = new ExcelUtil<WBusiness>(WBusiness.class);
        return util.exportExcel(list, "业务范围数据");
    }

    /**
     * 新增业务范围
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业务范围
     */
    @RequiresPermissions("custom:business:add")
    @Log(title = "业务范围", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WBusiness wBusiness)
    {
        return toAjax(wBusinessService.insertWBusiness(wBusiness));
    }

    /**
     * 修改业务范围
     */
    @RequiresPermissions("custom:business:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WBusiness wBusiness = wBusinessService.selectWBusinessById(id);
        mmap.put("wBusiness", wBusiness);
        return prefix + "/edit";
    }

    /**
     * 修改保存业务范围
     */
    @RequiresPermissions("custom:business:edit")
    @Log(title = "业务范围", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WBusiness wBusiness)
    {
        return toAjax(wBusinessService.updateWBusiness(wBusiness));
    }

    /**
     * 删除业务范围
     */
    @RequiresPermissions("custom:business:remove")
    @Log(title = "业务范围", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wBusinessService.deleteWBusinessByIds(ids));
    }

}
